package com.leetcode;

/**
 * 821. 字符的最短距离
 * 2022-04-19-每日一题
 * 双层循环暴力破解
 *
 * @author fy
 * @date 2022/4/20 20:33
 */
public class Solution821 {

    public int[] shortestToChar(String s, char c) {
        int n = s.length();
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            int len = n + 1;
            for (int j = 0; j < n; j++) {
                if (s.charAt(j) == c) {
                    int tp = Math.abs(j - i);
                    if (len > tp) {
                        res[i] = tp;
                        len = tp;
                    }
                }
            }
        }
        return res;
    }

}
